import unittest, os
from forTest2 import *
from HTMLTestRunner import HTMLTestRunner

# 创建一个测试套件 == list
suite = unittest.TestSuite()

# 添加测试用例（子元素）到测试套件（集合）
# 方法1
# suite.addTest(forTestTest('test_2'))
# suite.addTest(forTestTest('test_1'))
# suite.addTest(forTestTest('test_3'))

# 方法2
# case = [forTestTest('test_2'),forTestTest('test_1'),forTestTest('test_3')]
# suite.addTests(case)

# 方法3
# test_dir = './'
# discover = unittest.defaultTestLoader.discover(start_dir=test_dir,pattern='forTe*.py')

# 方法4
# suite.addTest(unittest.TestLoader().loadTestsFromTestCase(forTestTest))
# suite.addTest(unittest.TestLoader().loadTestsFromName('forTest2.forTestTest'))

# 套件通过TextTestRunner对象进行运行≈unittest.main()
# runner = unittest.TextTestRunner()
# runner.run(suite)

# 测试报告
report_name = '测试报告名称'
report_title = '测试报告标题'
report_desc = '测试报告描述'
report_path = './report/'
report_file = report_path+'report2.html'
if not os.path.exists(report_path):
    os.mkdir(report_path)
else:
    pass
with open(report_file,'wb') as report:
    suite.addTest(unittest.TestLoader().loadTestsFromName('forTest2.forTestTest'))
    # 套件通过TextTestRunner对象进行运行≈unittest.main()
    # 如果解和HTMLTestRunner使用，则需要调用HTMLTestRunner中的运行器
    runner = HTMLTestRunner(stream=report,title=report_title,description=report_desc)
    runner.run(suite)
report.close()

